<?php

class Model_Testimonial extends Zend_Db_Table_Abstract {

    protected $_name = 'testimonials';

    public function fetchTestimonial($where = "", $limit = "", $offset = "0") {
	$select = $this->select()
			->where("active = '1'")
			->order('sortorder ASC');
	if ($limit != "") {
	    $select->limit($limit, $offset);
	}
	return $this->fetchAll($select);
    }

    public function getTestimonailCount() {
	$select = $this->select();
	$select->from($this, array('count(id) as amount'))
		->where("active = '1'");
	$rows = $this->fetchAll($select);
	return($rows[0]->amount);
    }

    /**
     * Function to get single testimonail randomly
     *
     * @param string $type Type field in the table testimonials
     * 
     * @return array
     */
    public function getRandomTestimonail($type = 'general') {
	$select = $this->select()
			->where("active = '1'")
			->where("type = '" . $type . "'")
			->order('RAND()')
			->limit('1');
	$rows = $this->fetchAll($select);

	return(Array('message' => $rows[0]->message, 'client' => $rows[0]->client));
    }

}

?>